
package upcoming.client.internal.xstream;

import upcoming.client.*;

import com.thoughtworks.xstream.XStream;
// import com.thoughtworks.xstream.converters.extended.ToStringConverter;
import com.thoughtworks.xstream.io.xml.DomDriver;
import com.thoughtworks.xstream.mapper.MapperWrapper;

public class XStreamFactory
{
	
	public static XStream createXStream() 
	{
		
		XStream xstream;
		
		xstream = new XStream(new DomDriver())
		{
			protected MapperWrapper wrapMapper(MapperWrapper next)
			{
				return new UpcomingMapper(next);
			}
		};
		
 		xstream.registerConverter(new CalendarConverter(), XStream.PRIORITY_VERY_HIGH);
 		
 		
		xstream.addImplicitCollection(Response.class, "events", "event", Event.class);
		xstream.addImplicitCollection(Response.class, "metroList", "metro", Metro.class);
		xstream.addImplicitCollection(Response.class, "categories", "category", Category.class);
		xstream.addImplicitCollection(Response.class, "venues", "venue", Venue.class);
		

		xstream.aliasField("event", Response.class, "events");
		xstream.aliasField("category", Response.class, "categories");
		xstream.aliasField("venue", Response.class, "venues");
		xstream.aliasField("metro", Response.class, "metroList");


 		
 		xstream.aliasAttribute("name", "name");
 		xstream.aliasAttribute("id", "id");
 		xstream.aliasAttribute("code", "code");
 		xstream.aliasAttribute("username", "username");
 		xstream.aliasAttribute("zip", "zip");
 		xstream.aliasAttribute("start_date", "startDate");
 		xstream.aliasAttribute("end_date", "endDate");
 		xstream.aliasAttribute("description", "description");
 		xstream.aliasAttribute("start_time", "startTime");
 		xstream.aliasAttribute("end_time", "endTime");
 		xstream.aliasAttribute("metro_id", "metroId");
 		xstream.aliasAttribute("venue_id", "venueId");
 		xstream.aliasAttribute("venue_name", "venueName");
 		xstream.aliasAttribute("venue_address", "venueAddress");
 		xstream.aliasAttribute("venue_city", "venueCity");
 		xstream.aliasAttribute("venue_state_name", "venueStateName");
 		xstream.aliasAttribute("venue_state_code", "venueStateCode");
 		xstream.aliasAttribute("venue_country_name", "venueCountryName");
 		xstream.aliasAttribute("venue_country_code", "venueCountryCode");
 		xstream.aliasAttribute("venue_country_id", "venueCountryId");
 		xstream.aliasAttribute("venue_zip", "venueZip");
 		xstream.aliasAttribute("venue_url", "venueUrl");
 		
 		xstream.aliasAttribute("state_name", "stateName");
 		xstream.aliasAttribute("state_code", "stateCode");
 		xstream.aliasAttribute("state_id", "stateId");
 		xstream.aliasAttribute("country_name", "countryName");
 		xstream.aliasAttribute("country_code", "countryCode");
 		xstream.aliasAttribute("country_id", "countryId");
 		
 		xstream.aliasAttribute("personal", "personal");
 		xstream.aliasAttribute("selfpromotion", "selfPromotion");
 		xstream.aliasAttribute("ticket_url", "ticketUrl");
 		xstream.aliasAttribute("ticket_free", "ticketFree");
 		xstream.aliasAttribute("photo_url", "photoUrl");
 		xstream.aliasAttribute("photourl", "photoUrl");
 		xstream.aliasAttribute("user_id", "userId");
 		xstream.aliasAttribute("date_posted", "datePosted");
 		xstream.aliasAttribute("category_id", "categoryId");
 		xstream.aliasAttribute("watchlist_count", "watchlistCount");
 		xstream.aliasAttribute("url", "url");
 		xstream.aliasAttribute("latitude", "latitude");
 		xstream.aliasAttribute("longitude", "longitude");
 		xstream.aliasAttribute("geocoding_precision", "geocodingPrecision");
 		xstream.aliasAttribute("geocoding_ambiguous", "geocodingAmbiguous");
 		xstream.aliasAttribute("stat", "status");
 		xstream.aliasAttribute("version", "version");
 		xstream.aliasAttribute("msg", "message");
 		
		xstream.alias("rsp", Response.class);
		xstream.alias("user", User.class);
		xstream.alias("token", Token.class);
		xstream.alias("category", Category.class);
		xstream.alias("watchlist", WatchlistItem.class);
		xstream.alias("group", Group.class);
		xstream.alias("event", Event.class);
		xstream.alias("venue", Venue.class);
		xstream.alias("metro", Metro.class);
		xstream.alias("country", Country.class);
		xstream.alias("state", State.class);
		xstream.alias("error", UpcomingError.class);
		
		
		return xstream;
		
	}
}
